package com.leyou.item.controller;

import com.leyou.item.pojo.Category;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 *
 * create by Rose on 2020/1/8
 */
@RestController
@RequestMapping("/category")
public class CategoryController {


    @Autowired
    private CategoryService categoryService ;


    /**
     *
     * 商品分类列表查询
     *
     * @param pid
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<List<Category>> queryCategoryByPid(@RequestParam("pid") Long pid){


        List<Category> list = categoryService.queryCategoryByPid(pid);
        /*if( list == null){
            // 没找到，返回404
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
        }*/
        // 找到返回200
        return ResponseEntity.ok(list);
    }


    /**
     *
     *  通过品牌id 查询商品分类
     *
     * @param bid
     * @return
     */
    @GetMapping("bid/{bid}")
    public ResponseEntity<List<Category>> queryByBrandId(@PathVariable("bid") Long bid){
        List<Category> list = this.categoryService.queryByBrandId(bid);
        return ResponseEntity.ok(list);
    }


    /**
     * 根据ids 查询商品分类结果
     *
     * @param ids
     * @return
     */
    @GetMapping("list/ids")
    public ResponseEntity<List<Category>> quryCategoryByIds(@RequestParam("ids") List<Long> ids) {
        List<Category> categoryList = categoryService.queryByIds(ids);
        return ResponseEntity.ok(categoryList);
    }


}
